home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-03 | 3.2 KB | 144 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { CFSStickPane.p }
- {}
- { Pane methods for the joystick pane. }
- {}
- { Copyright © 1995, Patrick Hew. All rights reserved. }
- {}
- {****************************************************}
-
-
- unit CFSStickPane;
-
- interface
-
- uses
- TCL, FSIntf;
-
- implementation
-
-
- { IFSStickPane }
- {}
- { Post: The stick pane has been initialized. }
-
- procedure CFSStickPane.IFSStickPane (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
-
- begin { IFSStickPane }
- IPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
-
- stickh := 0;
- stickv := 0;
-
- { oldMousePt is initialized in the DoCommand method. }
-
- end; { IFSStickPane }
-
-
- { Draw }
- {}
- { Post: The stick pane has been drawn. }
-
- procedure CFSStickPane.Draw (var area: Rect);
-
- begin { Draw }
- MoveTo(kStickHalfWidth, kStickHalfHeight);
- Line(stickh, stickv);
- end; { Draw }
-
-
- { InitOldMousePt }
- {}
- { Pre: The game director has received the command to take control. }
- { Post: The old mouse position has been initialized, ready for control }
- { measurement on the next event loop. }
-
- procedure CFSStickPane.InitOldMousePt;
-
- var
- theMousePt: Point;
-
- begin { InitOldMousePt }
- { Remember - Never pass an instance variable }
- { by reference. }
- Prepare;
- GetMouse(theMousePt);
- oldMousePt := theMousePt;
- end; { InitOldMousePt }
-
-
- { GetControl }
- {}
- { Post: aBankChange and aAOAChange are respectively the change in }
- { bank and AOA, based on the offset of the mouse from the centre }
- { of the stick pane. }
-
- procedure CFSStickPane.GetControl (var aBankChange, aAOAChange: Real);
-
- var
- currMousePt: Point;
- offseth, offsetv: Integer;
- oldstickh: StickHorRange;
- oldstickv: StickVerRange;
-
- begin { GetControl }
- oldstickh := stickh;
- oldstickv := stickv;
-
- { Take coordinates relative to the current GrafPort. }
-
- Prepare;
- GetMouse(currMousePt);
-
- offseth := currMousePt.h - oldMousePt.h;
- offsetv := currMousePt.v - oldMousePt.v;
-
- oldMousePt := currMousePt;
-
- { Correct for overlarge changes in mouse position. }
-
- if offseth < -kStickHalfWidth then begin
- stickh := -kStickHalfWidth;
- end { if }
- else if offseth > kStickHalfWidth then begin
- stickh := kStickHalfWidth;
- end { else if }
- else begin
- stickh := StickHorRange(offseth);
- end; { else }
-
- if offsetv < -kStickHalfHeight then begin
- stickv := -kStickHalfHeight;
- end { if }
- else if offsetv > kStickHalfHeight then begin
- stickv := kStickHalfHeight;
- end { else if }
- else begin
- stickv := StickVerRange(offsetv);
- end; { else }
-
- if (oldstickh <> stickh) or (oldstickv <> stickv) then begin
- Refresh;
- end; { else }
-
- aBankChange := pi * stickh / (kStickHalfWidth * 12); { 15° bank change per frame. }
- aAOAChange := pi * stickv / (kStickHalfHeight * 12); { 15° AOA change per frame. }
-
- end; { GetControl }
-
-
- { CentreStick }
- {}
- { Post: The stick has been centred and refreshed. }
-
- procedure CFSStickPane.CentreStick;
-
- begin { CentreStick }
- stickh := 0;
- stickv := 0;
- Refresh;
- end; { CentreStick }
-
-
- end. { CFSStickPane }